package org.balthie.cal.impl.cmd;

import org.balthie.cal.core.AbsCommand;
import org.balthie.cal.core.ILiterallyNumb;
import org.balthie.cal.impl.cmd.spec.CmdSizeSpecs;
import org.balthie.cal.impl.cmd.spec.CmdsLiterallyRegexSpecs.CmdsLiterallyRegexSpec;
import org.balthie.cal.impl.cmd.spec.PrevCmdTypeSpecs;

public class NumbCmd extends AbsCommand implements ILiterallyNumb {
	private static final String LEGAL_PATTERN1 = "^0$";
	private static final String LEGAL_PATTERN2 = "^\\d*[\\+\\-\\✖\\➗]{1}0$";

	public NumbCmd(String literallyNumb) {
		super(literallyNumb);
		// 数字前只能是数字、运算符 或 未输入指令
		this.legalSpecs = PrevCmdTypeSpecs.IS_NUMB.or(PrevCmdTypeSpecs.IS_MATHOPT).or(CmdSizeSpecs.EMPTY)
				// case 左式只有一个0
				.not(new CmdsLiterallyRegexSpec(LEGAL_PATTERN1, "数值0后不能接其它数字"))
				// case 右式只有一个0
				.not(new CmdsLiterallyRegexSpec(LEGAL_PATTERN2, "数学运算符后只能接一个0"));
	}

	@Override
	public String getTips() {
		return this.literallyContent;
	}
}
